package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.*;

/**
 * Created by Student on 18.08.2014.
 */
public class BankApplication {

    public static void main(String[] args) {
        Bank bank = new Bank();

        try {
            BankService.addClient(bank, new Client("Alex", Gender.MALE, new SavingAccount(10)));
            BankService.addClient(bank, new Client("Eugene", Gender.MALE, new SavingAccount(10)));
            BankService.addClient(bank, new Client("Anna", Gender.FEMALE, new CheckingAccount(20, 50)));
            BankService.addClient(bank, new Client("Igor", Gender.MALE, new CheckingAccount(17, 10)));
            BankService.addClient(bank, new Client("Alina", Gender.FEMALE,new CheckingAccount(10)));
            BankService.addClient(bank, new Client("Alina", Gender.FEMALE,new CheckingAccount(15)));
        } catch (ClientExistsException e) {
            System.out.println("Client exists");
        }

        modifyBank(bank);
        printBalance(bank);
        BankService.printMaximumAmountToWithdraw(bank);

    }


    private static void modifyBank(Bank bank)  {
        for (Client client: bank.getClients()){
            try {
                client.getAccounts().withdraw(50);
            }
            catch (OverDraftLimitExceededException e){
                System.out.println("account "+e.getClientAccount()+" can withdraw maximum "+e.maxMoney());
            }
            catch (NotEnoughFundsException e){
                System.out.println("client has not enough money");
            }
        }

    }

    private static void printBalance(Bank bank) {
        System.out.println("Accounts' balance");
        for (Client client : BankService.getClients(bank)) {
            System.out.println(client.getAccounts().getBalance());
        }
    }
}
